
$(document).ready(function(){
    getCourierOrderList();
});

function getCourierOrderList() {
    $.ajax({
        type: "post",
        url: '/courier/getCourierAllOrderList.do',
        dataType: "json",
        data: {
        },
        success: function(resp){
            console.log(resp);
            if(resp.result==="success"){
                showOrderList(resp.list);
                showWaitSending();
            }else{
                console.log("getMepOrderListERROR!");
            }
        }
    });
}

function showOrderList(list) {
    var html = "";
    for(var i=0;i<list.length;i++){
        var k = 3;
        if(list[i].order_status==='FINISHED'){
            html = html+" <li style='display: none' class='mep_order "+list[i].order_status+"'>\n" +
                "<div class=\"order_title\">" +
                "<h1>订单号"+list[i].order_no+"</h1>" +
                "<span>"+list[i].create_time+"</span>" +
                "</div>" +
                "<div class=\"order_content\" onclick=\"location.href=ctx+'/courier/toCourierFinishedOrder.do?order_no="+list[i].order_no+"'\" >" ;
            if((list[i].order_details).length<k){
                k = (list[i].order_details).length;
            }
            for(var j=0;j<k;j++){
                html = html+ "<div class=\"order_img\"><img src="+list[i].order_details[j].goods_img+" width=\"60\" height=\"40\" /></div>";
            }

            html = html+ "<div class=\"order_price\">" +
                "<h1>共"+list[i].order_details.length+"件商品</h1>" +
                "<p>合计¥"+list[i].order_price_final+"</p>" +
                "<i class=\"iconfont icon-jiantou\"></i>" +
                "</div>" +
                "</div>";

            html = html+"<div class=\"order_logistics_btns shopper\">\n" +
                "<h1>店铺名称："+list[i].customer_name+"</h1>\n" +
                "<p>"+list[i].address+"</p>"+
                "<a href=\"tel:"+list[i].mobile+"\" style=\"float: right\">联系店家</a>"+
                "</div></li>";
        }else{
            html = html+" <li style='display: none' class='mep_order "+list[i].order_status+"'>\n" +
                "<div class=\"order_title\">" +
                "<h1>订单号"+list[i].order_no+"</h1>" +
                "<span>"+list[i].create_time+"</span>" +
                "</div>" +
                "<div class=\"order_content\" onclick=\"location.href=ctx+'/courier/toSingOrderPage.do?order_no="+list[i].order_no+"'\" >" ;
            if((list[i].order_details).length<k){
                k = (list[i].order_details).length;
            }
            for(var j=0;j<k;j++){
                html = html+ "<div class=\"order_img\"><img src="+list[i].order_details[j].goods_img+" width=\"60\" height=\"40\" /></div>";
            }

            html = html+ "<div class=\"order_price\">" +
                "<h1>共"+list[i].order_details.length+"件商品</h1>" +
                "<p>合计¥"+list[i].order_price+"</p>" +
                "<i class=\"iconfont icon-jiantou\"></i>" +
                "</div>" +
                "</div>";

            html = html+"<div class=\"order_logistics_btns shopper\">\n" +
                "<h1>店铺名称："+list[i].customer_name+"</h1>\n" +
                "<p>"+list[i].address+"</p>"+
                "<a  style=\"float: right\" onclick=\"location.href=ctx+'/courier/toSingOrderPage.do?order_no="+list[i].order_no+"'\">开始签收</a>"+
                "<a href=\"tel:"+list[i].mobile+"\" style=\"float: right\">联系店家</a>"+
                "</div></li>";
        }



    }
    $('#order_list').html(html);
}

//显示等待配送
function showWaitSending() {
    $(".mep_order").hide();
    $(".order_status").removeClass('onthis');
    $('#status1').addClass('onthis');
    $('.WAITING_FOR_DELIVERY').show();
}

//显示已完成订单
function showFinished() {
    $(".mep_order").hide();
    $(".order_status").removeClass('onthis');
    $('#status2').addClass('onthis');
    $('.FINISHED').show();
}